package com.ns002.yigou.quote.common.scheduled;

import com.ns002.yigou.quote.common.task.LoadRealTimeQuoteTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author xu
 * @Date 2017/7/27 0027 上午 11:13
 * 行情定时抓取
 */
@Component
public class EbuyQuoteScheduled {

    private static Logger log = LoggerFactory.getLogger("ebuy-quote-task");
    LoadRealTimeQuoteTask quoteTask;

    @Value("${quote.save}")
    private boolean quoteSvae;

    public EbuyQuoteScheduled(@Autowired LoadRealTimeQuoteTask quoteTask){
        this.quoteTask = quoteTask;
        loadToken();
    }

    /**
     * 500毫秒抓取行情
     */
    @Scheduled(fixedRate = 500)
    public void timerRate() {

        if(!quoteSvae){
            return;
        }

        quoteTask.loadEBuy();
    }

    /**
     * 十分钟刷新行情token
     */
    @Scheduled(cron="0 0/10 * * * ?")
    public void loadToken(){
        log.error("读取token");
        quoteTask.loadEBuyQuoteToken();
    }


}
